package master.user;

import javax.annotation.Resource;
import org.springframework.stereotype.Repository;
import chopin.util.TableUtil;
import chopin.util.TableUtil.TableDecimal;
import com.xunlei.jdbc.JdbcTemplate;

@Repository
public class UserDao {

    // @Resource(name = "jdbcTemplateOAuth")
    // protected JdbcTemplate jdbcTemplateOAuth;jdbcTemplate_xlpan_oauth
    @Resource(name = "jdbcTemplate_user")
    protected JdbcTemplate jdbcTemplate_user;

    public User getUser(String userId) {
        String sql = "SELECT * FROM user? WHERE user_id=?";
        return jdbcTemplate_user.queryForObject(sql, User.class, TableUtil.getTableDecimalIndex(TableDecimal.user, userId), userId);
    }

    public void setUser(User user) {
        String sql = "insert into user? set user_id=?,nick=?,name=?,avatar_url=?,avatar_url_big=? on duplicate key update nick=?,name=?,avatar_url=?,avatar_url_big=?";
        jdbcTemplate_user.update(sql, TableUtil.getTableDecimalIndex(TableDecimal.user, user.getUser_id()), user.getUser_id(), user.getNick(), user.getName(), user.getAvatar_url(),
                user.getAvatar_url_big(), user.getNick(), user.getName(), user.getAvatar_url(), user.getAvatar_url_big());
    }
}
